/*
 * ActionKeysDispatcher.java
 *
 * Created on 5 mai 2007, 23:56
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package courselog;

import ewe.ui.Control;
import ewe.ui.Event;
import ewe.ui.EventListener;
import ewe.ui.Gui;
import ewe.ui.KeyEvent;

/**
 *
 * @author rigal
 */
public class ActionKeysDispatcher implements EventListener {
    
    protected Control actLeft;
    protected Control actRight;
    
    public void setLeftAndRight(Control cL, Control cR) {
        actLeft=cL;
        actRight=cR;
    }
    
    public void onEvent(Event ev) {
        if(ev instanceof KeyEvent) {
            KeyEvent kev= (KeyEvent) ev;
            if((kev.key=='p')&&(kev.type==KeyEvent.KEY_RELEASE)) {
                // This happens with left button
                Gui.takeFocus(actLeft,Gui.ByRequest);
                if(actLeft.menuIsActive()) {
                    actLeft.closeMenu();
                } else {
                    actLeft.doAction(Gui.ByKeyboard);
                }
            }else if((kev.key=='q')&&(kev.type==KeyEvent.KEY_RELEASE)){
                // This happens with right button
                Gui.takeFocus(actRight,Gui.ByRequest);
                if(actRight.menuIsActive()) {
//                    CourseLogAppForm.dbgL.addToLog("\nright- menu active");
                    actRight.closeMenu();
                } else {
                    actRight.doAction(Gui.ByKeyboard);
                }
            }
        }
    }
    
    
    
}
